package com.cyzy.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dao.RoleMenu;
import com.cyzy.mapper.RoleManageMapper;
import com.cyzy.service.RoleManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleManageServiceImpl implements RoleManageService {

    @Autowired
    private RoleManageMapper roleManageMapper;

    @Override
    public Page<RoleMenu> selectRoleMenu(RoleMenu roleMenu, int pageSize, int pageNum){
        Page<RoleMenu> page = new Page<>(pageNum, pageSize);
        return roleManageMapper.selectRoleMenu(page,roleMenu.getRoleId(),roleMenu.getRoleName(),roleMenu.getDescription(),
                roleMenu.getRoleStatus(),roleMenu.getCreateTime(),roleMenu.getMenuId(),roleMenu.getMenus());
    }
    @Override
    public int addRoleMenu(RoleMenu roleMenu){
        roleManageMapper.deleteAllRoleMenu(roleMenu.getRoleId());
        return roleManageMapper.addRoleMenu(roleMenu.getRoleId(),roleMenu.getMenuIds());
    }

    @Override
    public List<RoleMenu> getRoleMenu(RoleMenu roleMenu){
        return roleManageMapper.getRoleMenu(roleMenu.getRoleId(),roleMenu.getMenuId());
    }
    @Override
    public List<RoleMenu> getRole(RoleMenu roleMenu){
        return roleManageMapper.getRole(roleMenu);
    }

    @Override
    public void insertRole(RoleMenu roleMenu){
        int affectedRows = roleManageMapper.insertRole(roleMenu);
        if (affectedRows > 0) {
            roleManageMapper.addRoleMenu(roleMenu.getRoleId(),roleMenu.getMenuIds());
        }
    }

    @Override
    public RoleMenu exitRole(RoleMenu roleMenu) {
        return roleManageMapper.existRole(roleMenu);
    }

    @Override
    public int deleteRole(List<Integer> id){
        return roleManageMapper.deleteRole(id);
    }

}
